package com.apes.fn.scm.insuranceRules;

import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @ClassName : InsuranceRuleRepository
 * @Description : 保险规则Dao层
 * @Author : WSJ
 * @Date: 2020-04-07 11:11
 */
public interface InsuranceRuleRepository extends CustomRepository<InsuranceRule, String> {
    /**
     * 根据定损方及保险公司查定损规则
     *
     * @param deptId           定损门店
     * @param insuranceCompany 保险公司
     * @return 规则
     */
    @Query(value = "select t.* from insurance_rule t where t.valid = 1 and " +
            " t.id in (select a.rule_id from s_rule_dept a where a.dept_id = :deptId) and t.insurance_company_id =:companyId", nativeQuery = true)
    InsuranceRule findByLossDept(@Param("deptId") String deptId, @Param("companyId") String insuranceCompany);
}
